#!/usr/bin/perl -w
#
#	$Id: epiphyte-mkdb.pl,v 1.1.1.1 2006/03/20 04:08:45 jfb Exp $
#
# canopy-mkdb.pl - rebuild the Canopy database

use strict;

use DBI;


my $dbh;

$dbh = DBI->connect($ARGV[0]) || die "Failed to connect to $ARGV[0]: ",
    DBI::errstr();

$dbh->do("DROP TABLE users");
$dbh->do("DROP TABLE sections");
$dbh->do("DROP TABLE forums");
$dbh->do("DROP TABLE threads");
$dbh->do("DROP TABLE posts");

$dbh->do("CREATE TABLE users (id INTEGER, name CHAR(32), passwd CHAR(32), last INTEGER, nbposts INTEGER)");

$dbh->do("CREATE TABLE sections (id INTEGER, name CHAR(32))") ||
	die "Failed to create forums table: ", $dbh->errstr(), "\n";
$dbh->do("CREATE TABLE forums (id INTEGER, section INTEGER, name CHAR(32), description CHAR(256), nbposts INTEGER)") ||
	die "Failed to create forums table: ", $dbh->errstr(), "\n";
$dbh->do("CREATE TABLE threads (id INTEGER, title CHAR(32), fid INTEGER)") ||
	die "Failed to create threads table: ", $dbh->errstr(), "\n";
$dbh->do("CREATE TABLE posts (id INTEGER, subject CHAR(32), tid INTEGER, post CHAR(1024), time INTEGER)") ||
	die "Failed to create posts table: ", $dbh->errstr(), "\n";


$dbh->do("INSERT INTO sections VALUES (1, 'General')") ||
	die "Failed to insert forum: ", $dbh->errstr(), "\n";

$dbh->do("INSERT INTO sections VALUES (2, 'Fauna')") ||
	die "Failed to insert forum: ", $dbh->errstr(), "\n";

$dbh->do("INSERT INTO sections VALUES (3, 'Flora')") ||
	die "Failed to insert forum: ", $dbh->errstr(), "\n";

# Standard forums
$dbh->do("INSERT INTO forums VALUES (1, 1, 'General', 'General discussions')") ||
	die "Failed to insert forum: ", $dbh->errstr(), "\n";

$dbh->do("INSERT INTO forums VALUES (2, 2, 'Amphibians', 'Discussions on amphibians')") ||
	die "Failed to insert forum: ", $dbh->errstr(), "\n";

$dbh->do("INSERT INTO forums VALUES (3, 2, 'Arthropods', 'Discussions on arthropods')") ||
	die "Failed to insert forum: ", $dbh->errstr(), "\n";

$dbh->do("INSERT INTO forums VALUES (4, 2, 'Fish', 'Discussion on fish')") ||
	die "Failed to insert forum: ", $dbh->errstr(), "\n";

$dbh->do("INSERT INTO forums VALUES (5, 2, 'Reptiles', '')") ||
	die "Failed to insert forum: ", $dbh->errstr(), "\n";

$dbh->do("INSERT INTO forums VALUES (6, 3, 'Bromeliads', 'Discussions on bromeliads')") ||
	die "Failed to insert forum: ", $dbh->errstr(), "\n";

$dbh->do("INSERT INTO forums VALUES (7, 3, 'Carnivorous Plants', 'Discussions on carnivorous plants')") ||
	die "Failed to insert forum: ", $dbh->errstr(), "\n";

$dbh->do("INSERT INTO forums VALUES (8, 3, 'Orchids', 'Discussions on orchids')") ||
	die "Failed to insert forum: ", $dbh->errstr(), "\n";

$dbh->do("INSERT INTO forums VALUES (9, 3, 'Tropicals', 'Discussions on miscellaneous tropical plants')") ||
	die "Failed to insert forum: ", $dbh->errstr(), "\n";

$dbh->do("INSERT INTO forums VALUES (10, 1, 'For Sale/Trade', 'Animals, plants and equipment for sale or trade')") ||
	die "Failed to insert forum: ", $dbh->errstr(), "\n";




$dbh->disconnect();

exit(0);
